package com.futures.investm.utils;

import android.content.Context;

import com.futures.investm.constant.BussConstant;
import com.avos.avoscloud.AVUser;

import tech.com.commoncore.utils.DataUtils;
import tech.com.commoncore.utils.FastUtil;
import tech.com.commoncore.utils.SPHelper;

/**
 * 作者: ChenPengBo
 * 时间: 2018-10-23
 * 描述: Cache缓存工具类
 */

public class CacheData {

    private static AVUser mAVUser;
//    private static User mUser;
    private static String mLoginUserId;//登录用户ID

    //APP是否第一次打开
    public static boolean isFirst(Context context) {
        return SPHelper.getBooleanSF(context, BussConstant.IS_FIRST + FastUtil.getVersionCode(context), true);
    }

    public static void setIsFirst(Context context, boolean isFirst) {
        SPHelper.setBooleanSF(context, BussConstant.IS_FIRST + FastUtil.getVersionCode(context), isFirst);
    }

    //是否已登录
    public static boolean isLogin(Context context) {
        mLoginUserId = getLoginUserId(context);
        return !DataUtils.isEmptyString(mLoginUserId);
    }

    public static AVUser getmAVUser() {
        return mAVUser;
    }

    public static void setmAVUser(AVUser mAVUser) {
        CacheData.mAVUser = mAVUser;
    }

    //获取登录用户ID
    public static String getLoginUserId(Context context) {
        if (!DataUtils.isEmptyString(mLoginUserId)) {
            return mLoginUserId;
        } else {
                return SPHelper.getStringSF(context, BussConstant.KEY_LOGIN_USER_ID, "");
        }
    }

    public static void setLoginUserId(Context context, String loginUserId) {
        mLoginUserId = loginUserId;
        SPHelper.setStringSF(context, BussConstant.KEY_LOGIN_USER_ID, loginUserId);
    }

    public static AVUser getLoginUser() {
        return mAVUser;
    }

    public static void setLoginUser(AVUser mAVUser) {
        CacheData.mAVUser = mAVUser;
    }


    //设置登录信息
    public static void initLoginAccount(Context context, String phone, String password) {
        setLoginAccount(context, phone);
        setLoginPassword(context, password);
    }

    //设置登录账号
    public static void setLoginAccount(Context context, String phone) {
        String signPhone = SignUtil.getAESEncodeString(phone);
        SPHelper.setStringSF(context, BussConstant.LOGIN_ACCOUNT, signPhone);
    }

    //获取登录账号
    public static String getLoginAccount(Context context) {
        String signPhone = SPHelper.getStringSF(context, BussConstant.LOGIN_ACCOUNT);
        return SignUtil.getAESDecodeString(signPhone);
    }

    //设置登录密码
    public static void setLoginPassword(Context context, String password) {
        String signPassword = SignUtil.getAESEncodeString(password);
        SPHelper.setStringSF(context, BussConstant.LOGIN_PASSWORD, signPassword);
    }

    //获取登录密码
    public static String getLoginPassword(Context context) {
        String signPassword = SPHelper.getStringSF(context, BussConstant.LOGIN_PASSWORD);
        return SignUtil.getAESDecodeString(signPassword);
    }




}
